package com.black.cat.jvm.classfile.constantpool.impl;

import com.black.cat.jvm.classfile.ClassReader;
import com.black.cat.jvm.classfile.constantpool.BaseConstantInfo;
import com.black.cat.jvm.classfile.constantpool.ConstantInfo;
import com.black.cat.jvm.common.CommonValue;

/**
 * @Author blackcat
 * @create 2021/8/12 9:23
 * @version: 1.0
 * @description:utf8编码字符串
 *
 * CONSTANT_Utf8_info {
 * u1 tag;
 * u2 length;
 * u1 bytes[length];
 * }
 */
public class ConstantInfoUft8 extends BaseConstantInfo implements ConstantInfo {

    public ConstantInfoUft8(ClassReader reader) {
        int length = reader.nextU2ToInt();// u2
        byte[] bytes = reader.nextBytes(length);
        value = new String(bytes);
    }

    @Override
    public int getTag() {
       return CommonValue.CONSTANT_POOL_TAG_UTF8;
    }
}
